<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>首页-游戏-惠玩</title>
		<link href="../../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../../css/home/home.css" />
		<link rel="stylesheet" type="text/css" href="../../css/iconfont.css" />
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<div class="benefit_title_left">
				<ul class="mui-table-view">
					<li class="mui-table-view-cell" id="userInfoHeader">
						<a href="#" style="padding: 0;background: transparent;text-decoration: none;border: none;">
							<img class="mui-media-object mui-pull-left" src="../../imgs/mainTab/index2.png" id="img" />
						</a>
					</li>
				</ul>
			</div>
			<div class="benefit_title_middle">
				<div class="middle_box" id="middle_box">
					<nav class="mui-bar-tab" id="mui-bar-tab">
						<a class="mui-tab-item mui-active" href="game.html">
							<span class="mui-tab-label">游戏</span>
						</a>
						<a class="mui-tab-item " href="benefitPlay.html">
							<span class="mui-tab-label">惠玩</span>
						</a>
					</nav>
				</div>
			</div>
			<div class="benefit_title_right" style="text-align: right;">
				<!--<button type="button" class="searchBtn" id="search"><span class="mui-icon  iconfont icon-sousuo2"></span></button>-->
				<button type="button" class="searchBtn" id="Scavenging"><span class="mui-icon mui-icon iconfont icon-saoyisaojianjiban"></span></button>
			</div>
			<div style="clear: both;"></div>
		</header>

		<div class="mui-content" style="background: red;margin-top: -50px;">
		</div>
		<script type="text/javascript" src="../../js/jquery.min.js"></script>
		<script src="../../js/mui.min.js"></script>
		<script type="text/javascript" src="js/webviewGroup.js"></script>
		<script>
			mui.init();
			var subpages = ['game.html', 'benefitPlay.html'];
			var subpages_style = {
				top: '45px',
				bottom: '0px'
			};
			var anishow = {};
			//创建子页面 
			mui.plusReady(function() {
				plus.screen.lockOrientation("portrait-primary"); //锁定竖屏正方向 

				var self = plus.webview.currentWebview();
				for(var i = 0; i < subpages.length; i++) {
					var temp = {};
					var sub = plus.webview.create(subpages[i], subpages[i], subpages_style);
					if(i > 0) {
						sub.hide();
					} else {
						temp[subpages[i]] = 'true';
						mui.extend(anishow, temp);
					}
					self.append(sub);
				}

			});
			//当前激活项 
			var activeTab = subpages[0];
			mui('.mui-bar-tab').on('tap', 'a', function(e) {
				var targetTab = this.getAttribute('href');
				if(targetTab == activeTab) {
					return;
				} else {
					//更换标题 
					if(mui.os.ios || anishow[targetTab]) {
						plus.webview.show(targetTab);
					} else {
						var temp = {};
						temp[targetTab] = 'true';
						mui.extend(anishow, temp);
						plus.webview.show(targetTab, 'fade-in', '300');
					}
					plus.webview.hide(activeTab);
					activeTab = targetTab;
				}
			})
			
			function initUserInfoLogin() {
				var userInfo = JSON.parse(localStorage.getItem('$users') || "{}");
				if(userInfo != "") {
					var tempImg = userInfo.selfFace || "";
					if(tempImg != "") {
						//			    			userInfoHeader.src = tempImg;
						$('#img').attr('src', tempImg);
					} else {
						userInfoHeader.src = "../imgs/user_my_info_bg.jpg";
					}
				} else {
					userInfoHeader.src = "../images/user_my_info_bg.jpg";
				}
			}

			function leftMenu() {
				mui.fire(main, 'menu:open')
			}
			var _user = JSON.parse(localStorage.getItem("$users"));
			userInfoHeader.addEventListener("tap", function() {
				if(_user == null) {
					mui.openWindow({
						url: '../login.html',
						id: 'login',
						preload: true,
						show: {
							aniShow: 'pop-in'
						},
						styles: {
							popGesture: 'hide'
						},
						waiting: {
							autoShow: false
						}
					});
				} else {
					leftMenu();
				}
			}, false)
			var firsts = null;
			mui.close = function back() {
				//首次按键，提示‘再按一次退出应用’  
				if(!firsts) {
					firsts = new Date().getTime();
					//		      mui.toast('再按一次退出应用');  
					setTimeout(function() {
						firsts = null;
					}, 500);
				} else {
					if(new Date().getTime() - firsts < 1000) {
						plus.runtime.quit();
					}
				}
			}
			var _user = JSON.parse(localStorage.getItem("$users"));
			//点击搜索打开页面
			mui("body").on('tap', '#search', function() {
				if(_user == null) {
					/*没登录*/
					var btnArray = ['跳转登录', '取消'];
					mui.confirm('是否登录', '登录', btnArray, function(e) {
						if(e.index == 0) {
							mui.openWindow({
								url: "../login.html",
								id: "home_login",
							});
						}
					});
				} else {
					mui.openWindow({
						url: 'index-search.html',
						id: 'index-search.html',
					});
				}
			});
			/*点击扫码*/
			mui("body").on('tap', '#Scavenging', function() {
				if(_user == null) {
					/*没登录*/
					var btnArray = ['跳转登录', '取消'];
					mui.confirm('是否登录', '登录', btnArray, function(e) {
						if(e.index == 0) {
							mui.openWindow({
								url: "../login.html",
								id: "home_login",
							});
						}
					});
				} else {
					mui.openWindow({
						url: 'barcode.html',
						id: 'index-barcode.html',
					});
				}
			});
			
			
		</script>
	</body>

</html>